﻿Type=Activity
Version=2.71
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Dim lsvCLLB As ListView
	
	Dim HttpJobTool As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormSelectCLLB")
	Activity.Title = "选择处理类别"
	
End Sub

Sub Activity_Resume
	RefreshData
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub RefreshData
	Dim sURL,sUser,sSession,sText As String
	
	sUser = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserCode)
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sText = "User=" & sUser & "&Session=" & sSession
	 
	sURL = PublicVar.GetServerUrl&"/getyjcllb"
	
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	
	ProgressDialogShow("正在获取数据，请稍候...")	
	
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				LoginSuccess(Job)
      End If
   Else
		LoginError(Job)
   End If
   Job.Release
End Sub

Sub LoginSuccess(Job As HttpJob)  
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	Dim lsRecords As List
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	lsRecords = PublicVar.GV_JSonTool.NextArray
	
	SetYJCLLB(lsRecords)

End Sub

Sub LoginError(Job As HttpJob)  
	Dim sMsg As String
	ProgressDialogHide
			
  Log("Error: " & Job.ErrorMessage)
	sMsg = "获取登陆科室数据失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
	
End Sub

Sub SetYJCLLB(lsRecords As List)
	Dim sBM,sMC As String
	Dim mapResult As Map
	
	lsvCLLB.Clear
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		sBM = mapResult.Get("CLLB")
		sMC = mapResult.Get("CLLBMC")
		
		lsvCLLB.AddSingleLine2(sBM & " " &sMC,mapResult)	

	Next

End Sub

Sub lsvCLLB_ItemClick (Position As Int, Value As Object)
	Dim sMsg As String
	Dim mapResult As Map
	ProgressDialogHide
	mapResult = Value
	
	sMsg = "已选择"&mapResult.Get("CLLB") & " " & mapResult.Get("CLLBMC")
	ToastMessageShow (sMsg, True)
	
	BHList.V_CLLBBM = mapResult.Get("CLLB")
	BHList.V_CLLBMC = mapResult.Get("CLLBMC")
	StartActivity("BHList")  '病人列表
End Sub


